#ifndef _QY_TCP_CLIENT_H
#define _QY_TCP_CLIENT_H

#include <cstddef>
#include <string>
#include "Noncopyable.h"

namespace qy
{

class TCPChannel;

class TCPClient : public Noncopyable
{
public:
    TCPClient(const char *remote, unsigned int port);
	virtual ~TCPClient();

	bool connect();
	bool connect(const char *remote, unsigned int port);
	void close();

	bool canSend(double timeout = 0.5);
	bool canReceive(double timeout = 0.5);
	int send(const char *data, int size);
	int receive(char *buffer, int size);

	bool fail(){ return m_channel == NULL; }

protected:
	TCPChannel *m_channel;
	std::string m_remote;
	unsigned int m_port;
};

}

#endif
